package com.jj.config;

import com.jj.service.MenuService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.awt.*;
import java.util.List;

@Component
public class MenuCacheConfig {
    @Resource
    private RedisTemplate<Object,Object> redisTemplate;
    @Resource
    private MenuService menuService;
    @PostConstruct
    public void init(){
        //获取全量有序的菜单
        List<Menu> menuAll = menuService.hqmenuAll("0");
        //先看看redis有没有
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        System.out.println("加载菜单");

        redisTemplate.delete("menus");
        System.out.println("加载菜单完成");
        redisTemplate.opsForValue().get("menus");

        redisTemplate.opsForValue().set("menus",menuAll);
    }
}
